package com.think.admin.oauth.rbac;

import com.think.common.enums.SysUserTypeEnum;
import lombok.AllArgsConstructor;
import org.springframework.security.core.CredentialsContainer;
import org.springframework.security.core.SpringSecurityCoreVersion;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Set;

/**
 * <p>
 * RBAC权限对象
 * </p>
 *
 * @author: xwj
 * @data: 2019-05-14
 */
@AllArgsConstructor
public class RbacUserDetails implements UserDetails, CredentialsContainer {
    private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;

    private final String userId;
    private final String username;
    private String password;
    private final SysUserTypeEnum type;
    private final String companyId;
    private final Set<RbacGrantedAuthority> authorities;
    private final boolean accountNonExpired;
    private final boolean accountNonLocked;
    private final boolean credentialsNonExpired;
    private final boolean enabled;

    public String getUserId() {
        return userId;
    }

    public SysUserTypeEnum getType() {
        return type;
    }

    public String getCompanyId() {
        return companyId;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    @Override
    public Set<RbacGrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public boolean isEnabled() {
        return enabled;
    }

    @Override
    public boolean isAccountNonExpired() {
        return accountNonExpired;
    }

    @Override
    public boolean isAccountNonLocked() {
        return accountNonLocked;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return credentialsNonExpired;
    }

    @Override
    public void eraseCredentials() {
        password = null;
    }
}
